﻿#pragma once

#include "DropBuilderForm.h"
#include "../../Server/MirEnvir/Envir.h"
#include <string>
#include <vector>
#include <stdexcept>
#include <any>
#include "../../stringhelper.h"
#include "../../tangible_filesystem.h"

using namespace Server::MirEnvir;

namespace Server::MirForms::DropBuilder
{
    class DropGenForm : public System::Windows::Forms::Form
    {
    private:
        std::string Gold = "0", GoldOdds;

        std::vector<DropItem*> Weapon = std::vector<DropItem*>(), Armour = std::vector<DropItem*>(), Helmet = std::vector<DropItem*>(), Necklace = std::vector<DropItem*>(), Bracelet = std::vector<DropItem*>(), Ring = std::vector<DropItem*>(), Amulet = std::vector<DropItem*>(), Belt = std::vector<DropItem*>(), Boot = std::vector<DropItem*>(), Stone = std::vector<DropItem*>(), Torch = std::vector<DropItem*>(), Potion = std::vector<DropItem*>(), Ore = std::vector<DropItem*>(), Meat = std::vector<DropItem*>(), CraftingMaterial = std::vector<DropItem*>(), Scrolls = std::vector<DropItem*>(), Gem = std::vector<DropItem*>(), Mount = std::vector<DropItem*>(), Book = std::vector<DropItem*>(), Nothing = std::vector<DropItem*>(), Script = std::vector<DropItem*>(), Reins = std::vector<DropItem*>(), Bells = std::vector<DropItem*>(), Saddle = std::vector<DropItem*>(), Ribbon = std::vector<DropItem*>(), Mask = std::vector<DropItem*>(), Food = std::vector<DropItem*>(), Hook = std::vector<DropItem*>(), Float = std::vector<DropItem*>(), Bait = std::vector<DropItem*>(), Finder = std::vector<DropItem*>(), Reel = std::vector<DropItem*>(), Fish = std::vector<DropItem*>(), Quest = std::vector<DropItem*>(), Awakening = std::vector<DropItem*>(), Pets = std::vector<DropItem*>(), Transform = std::vector<DropItem*>();

        std::vector<std::vector<DropItem*>> ItemLists;
        std::vector<ListBox*> ItemListBoxes;

    public:
        virtual ~DropGenForm()
        {
            delete components;
            delete listBoxMonsters;
            delete textBoxDropList;
            delete listBoxWeapon;
            delete tabControlSeperateItems;
            delete tabPageWeapon;
            delete tabPageArmour;
            delete tabPageHelmet;
            delete tabPageNecklace;
            delete tabPageBracelet;
            delete tabPageRing;
            delete tabPageAmulet;
            delete tabPageBelt;
            delete tabPageBoot;
            delete tabPageStone;
            delete tabPageTorch;
            delete tabPagePotion;
            delete tabPageOre;
            delete labelItemOdds;
            delete buttonAdd;
            delete buttonEdit;
            delete tabPageMeat;
            delete tabPageCraftingMaterial;
            delete tabPageScroll;
            delete tabPageGem;
            delete tabPageMount;
            delete tabPageBook;
            delete listBoxArmour;
            delete listBoxHelmet;
            delete listBoxNecklace;
            delete listBoxBracelet;
            delete listBoxRing;
            delete listBoxAmulet;
            delete listBoxBelt;
            delete listBoxBoot;
            delete listBoxStone;
            delete listBoxTorch;
            delete listBoxPotion;
            delete listBoxOre;
            delete listBoxMeat;
            delete listBoxCraftingMaterial;
            delete listBoxScroll;
            delete listBoxGem;
            delete listBoxMount;
            delete listBoxBook;
            delete textBoxMinLevel;
            delete textBoxMaxLevel;
            delete label1;
            delete textBoxItemOdds;
            delete labelRange;
            delete labelGold;
            delete textBoxGoldOdds;
            delete labelGoldOdds;
            delete groupBoxGold;
            delete textBoxGoldAmount;
            delete groupBoxItem;
            delete tabPageNothing;
            delete listBoxNothing;
            delete checkBoxCap;
            delete buttonUpdateGold;
            delete labelMobLevel;
            delete labelMonsterList;
            delete tabPageScript;
            delete tabPageReins;
            delete tabPageBells;
            delete tabPageSaddle;
            delete tabPageRibbon;
            delete tabPageMask;
            delete tabPageFood;
            delete tabPageHook;
            delete tabPageFloat;
            delete tabPageBait;
            delete tabPageFinder;
            delete tabPageReel;
            delete tabPageFish;
            delete tabPageQuest;
            delete listBoxSaddle;
            delete listBoxBait;
            delete listBoxBells;
            delete listBoxQuest;
            delete listBoxReel;
            delete listBoxReins;
            delete listBoxRibbon;
            delete listBoxFinder;
            delete listBoxFish;
            delete listBoxFloat;
            delete listBoxFood;
            delete listBoxHook;
            delete listBoxMask;
            delete listBoxScript;
            delete textBoxSearch;
            delete label2;
            delete QuestOnlyCheckBox;
            delete tabPageAwakening;
            delete listBoxAwakening;
            delete tabPagePets;
            delete tabPageTransform;
            delete listBoxPets;
            delete listBoxTransform;
        }

        DropGenForm();

        // Gets server data
        Server::MirEnvir::Envir *getEnvir() const;

        // Updates the drop file text
    private:
        void UpdateDropFile();

        // Item tab change, draw appropriate items
        void tabControlSeperateItems_SelectedIndexChanged(std::any sender, EventArgs *e);

        // Update the results to show them filtered
        void FilterValueChange(std::any sender, EventArgs *e);

        // Add the item to the drop list
        void buttonAdd_Click(std::any sender, EventArgs *e);

        // Choose another monster.
        void listBoxMonsters_SelectedItemChanged(std::any sender, EventArgs *e);

        // Load the monster.txt drop file.
        void LoadDropFile(bool edit);

        // Save the monster.txt drop file
        void SaveDropFile();

        //Edit gold amount/odds
        void GoldDropChange(std::any sender, EventArgs *e);

        //Switch to Edit mode
        void buttonEdit_Click(std::any sender, EventArgs *e);

        //Cap item range to monsters level
        void checkBoxCap_CheckedChanged(std::any sender, EventArgs *e);

        void buttonUpdateGold_Click(std::any sender, EventArgs *e);

        void textBoxSearch_TextChanged(std::any sender, EventArgs *e);


        /// <summary>
        /// Required designer variable.
        /// </summary>
        System::ComponentModel::IContainer *components = nullptr;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
    protected:
        void Dispose(bool disposing) override;

        #pragma region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
    private:
        void InitializeComponent();

        #pragma endregion

        System::Windows::Forms::ListBox *listBoxMonsters;
        System::Windows::Forms::TextBox *textBoxDropList;
        System::Windows::Forms::ListBox *listBoxWeapon;
        System::Windows::Forms::TabControl *tabControlSeperateItems;
        System::Windows::Forms::TabPage *tabPageWeapon;
        System::Windows::Forms::TabPage *tabPageArmour;
        System::Windows::Forms::TabPage *tabPageHelmet;
        System::Windows::Forms::TabPage *tabPageNecklace;
        System::Windows::Forms::TabPage *tabPageBracelet;
        System::Windows::Forms::TabPage *tabPageRing;
        System::Windows::Forms::TabPage *tabPageAmulet;
        System::Windows::Forms::TabPage *tabPageBelt;
        System::Windows::Forms::TabPage *tabPageBoot;
        System::Windows::Forms::TabPage *tabPageStone;
        System::Windows::Forms::TabPage *tabPageTorch;
        System::Windows::Forms::TabPage *tabPagePotion;
        System::Windows::Forms::TabPage *tabPageOre;
        System::Windows::Forms::Label *labelItemOdds;
        System::Windows::Forms::Button *buttonAdd;
        System::Windows::Forms::Button *buttonEdit;
        System::Windows::Forms::TabPage *tabPageMeat;
        System::Windows::Forms::TabPage *tabPageCraftingMaterial;
        System::Windows::Forms::TabPage *tabPageScroll;
        System::Windows::Forms::TabPage *tabPageGem;
        System::Windows::Forms::TabPage *tabPageMount;
        System::Windows::Forms::TabPage *tabPageBook;
        System::Windows::Forms::ListBox *listBoxArmour;
        System::Windows::Forms::ListBox *listBoxHelmet;
        System::Windows::Forms::ListBox *listBoxNecklace;
        System::Windows::Forms::ListBox *listBoxBracelet;
        System::Windows::Forms::ListBox *listBoxRing;
        System::Windows::Forms::ListBox *listBoxAmulet;
        System::Windows::Forms::ListBox *listBoxBelt;
        System::Windows::Forms::ListBox *listBoxBoot;
        System::Windows::Forms::ListBox *listBoxStone;
        System::Windows::Forms::ListBox *listBoxTorch;
        System::Windows::Forms::ListBox *listBoxPotion;
        System::Windows::Forms::ListBox *listBoxOre;
        System::Windows::Forms::ListBox *listBoxMeat;
        System::Windows::Forms::ListBox *listBoxCraftingMaterial;
        System::Windows::Forms::ListBox *listBoxScroll;
        System::Windows::Forms::ListBox *listBoxGem;
        System::Windows::Forms::ListBox *listBoxMount;
        System::Windows::Forms::ListBox *listBoxBook;
        System::Windows::Forms::TextBox *textBoxMinLevel;
        System::Windows::Forms::TextBox *textBoxMaxLevel;
        System::Windows::Forms::Label *label1;
        System::Windows::Forms::TextBox *textBoxItemOdds;
        System::Windows::Forms::Label *labelRange;
        System::Windows::Forms::Label *labelGold;
        System::Windows::Forms::TextBox *textBoxGoldOdds;
        System::Windows::Forms::Label *labelGoldOdds;
        System::Windows::Forms::GroupBox *groupBoxGold;
        System::Windows::Forms::TextBox *textBoxGoldAmount;
        System::Windows::Forms::GroupBox *groupBoxItem;
        System::Windows::Forms::TabPage *tabPageNothing;
        System::Windows::Forms::ListBox *listBoxNothing;
        System::Windows::Forms::CheckBox *checkBoxCap;
        System::Windows::Forms::Button *buttonUpdateGold;
        System::Windows::Forms::Label *labelMobLevel;
        System::Windows::Forms::Label *labelMonsterList;
        System::Windows::Forms::TabPage *tabPageScript;
        System::Windows::Forms::TabPage *tabPageReins;
        System::Windows::Forms::TabPage *tabPageBells;
        System::Windows::Forms::TabPage *tabPageSaddle;
        System::Windows::Forms::TabPage *tabPageRibbon;
        System::Windows::Forms::TabPage *tabPageMask;
        System::Windows::Forms::TabPage *tabPageFood;
        System::Windows::Forms::TabPage *tabPageHook;
        System::Windows::Forms::TabPage *tabPageFloat;
        System::Windows::Forms::TabPage *tabPageBait;
        System::Windows::Forms::TabPage *tabPageFinder;
        System::Windows::Forms::TabPage *tabPageReel;
        System::Windows::Forms::TabPage *tabPageFish;
        System::Windows::Forms::TabPage *tabPageQuest;
        System::Windows::Forms::ListBox *listBoxSaddle;
        System::Windows::Forms::ListBox *listBoxBait;
        System::Windows::Forms::ListBox *listBoxBells;
        System::Windows::Forms::ListBox *listBoxQuest;
        System::Windows::Forms::ListBox *listBoxReel;
        System::Windows::Forms::ListBox *listBoxReins;
        System::Windows::Forms::ListBox *listBoxRibbon;
        System::Windows::Forms::ListBox *listBoxFinder;
        System::Windows::Forms::ListBox *listBoxFish;
        System::Windows::Forms::ListBox *listBoxFloat;
        System::Windows::Forms::ListBox *listBoxFood;
        System::Windows::Forms::ListBox *listBoxHook;
        System::Windows::Forms::ListBox *listBoxMask;
        System::Windows::Forms::ListBox *listBoxScript;
        System::Windows::Forms::TextBox *textBoxSearch;
        System::Windows::Forms::Label *label2;
        System::Windows::Forms::CheckBox *QuestOnlyCheckBox;
        System::Windows::Forms::TabPage *tabPageAwakening;
        System::Windows::Forms::ListBox *listBoxAwakening;
        System::Windows::Forms::TabPage *tabPagePets;
        System::Windows::Forms::TabPage *tabPageTransform;
        System::Windows::Forms::ListBox *listBoxPets;
        System::Windows::Forms::ListBox *listBoxTransform;

    };
}
